<?php
// +--------------------------------------------------------------------------
// | ISDCE [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2017 载攸道 版权所有 <TEL:086-010-57209502>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * [ 后台模块 ]
 */
namespace Api\Controller;
use Think\Controller;

/**
 * 菜单API
 */
class MenuController extends Controller{
	
	public function info(){
		
		$m_common_menu =M('common_menu');
		$map['name'] = array("like","%Admin/Menu/Manage%");
		$list = $m_common_menu->where($map)->select();
		dump($list);die;
		
		$m_log =M('log');
	
		$data = $m_log->find(4);
		$datas = unserialize($data['xml']);
		
		$data =  self::xml2array($datas);
		dump($datas);
		dump($data);
	}
	
	/**
	 * 将xml转为array
	 * @param  string 	$xml xml字符串
	 * @return array    转换得到的数组
	 */
	protected function xml2array($xml){   
		//禁止引用外部xml实体
		libxml_disable_entity_loader(true);
		$result= json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);        
		return $result;
	}
	
	/**
	 * API更新菜单
	 */
    public function Update(){
		
	
		
		$m_common_menu = M('common_menu');
		
		//获得上级信息
		$map_top['id'] = I('param.id');
		$map_top['status'] = 1;
		$data = $m_common_menu->where($map_top)->find();
		
		//获得菜单信息
		$map['fmid'] = $map_top['id'];
		$map['status'] = 1;
		
		$list = $m_common_menu->where($map)->order('sort desc')->select();
		
		foreach($list as $i=>$k){
			
			$down_map['fmid'] = $list[$i]['id'];
			$down_map['status'] = 1;
		
			$list[$i]['down'] = $m_common_menu->where($down_map)->order('sort desc')->select();
		
			
		}
		
		$data['down'] = $list;
		
		$this->ajaxReturn($data);
		
	}
	
	
}